#pragma once
#include "ResourceBase.h"
#include "Mesh.h"
#include "Material.h"
#include "UnitDerive.h"
namespace mini
{
	class CModel : public CResourceBase
	{
		friend class CActor;
		friend class CResourceManager;
		struct  MeshInfo
		{
			CTexture* pTexture = nullptr;
			CMeshUnit* pMeshUnit = nullptr; 
			CMaterialUnit* pUnit = nullptr;
		};
	public:
		CModel();
		virtual ~CModel();
		void pushMeshUnit(CMeshUnit* pMesh);
		void pushTexture(int nGround, const std::string& name, CResourceBase* pResource);
		void popMesh(CMesh* pMesh);
		void popMesh(UINT32 resId);
		void popMesh(const std::string& szMeshName);
		void buildMaterialUnit(const std::string& strMaterial);
		const std::map<UINT32, MeshInfo>& getMeshInfoMap() const;
		BYTE* getSdkMeshData();
		const std::map<std::string, CTexture*>& getGroundTextures(int nIndex);

	private:
		MeshInfo* getMeshInfoPtr(CMesh* pMesh);
		void mergeBoundBox();

	private:
		CBoundBox							mBoundBox;
		CMaterialUnit*						mpMaterialUnit = nullptr;
		std::map<int,std::map<std::string, CTexture*>>	mTextures;
		std::map<UINT32, MeshInfo>			mpMeshesInfo;
		BYTE*	mpSdkMeshInfo = nullptr;
	};
}